package bma.common.thrift.ai;

import org.apache.thrift.TBase;
import org.apache.thrift.TFieldIdEnum;

import bma.common.langutil.ai.stack.AIStack;
import bma.common.langutil.ai.stack.AIStackConvert;

public class AIBaseStack<TYPE> extends AIStackConvert<TYPE, TBase> {

	protected TBase result;

	public AIBaseStack(AIStack<TBase> delegate, TBase result) {
		super(delegate);
		this.result = result;
	}

	public TBase getResult() {
		return result;
	}

	public void setResult(TBase result) {
		this.result = result;
	}

	@Override
	protected boolean convert(TYPE r) {
		if (result == null) {
			return successConvert(null);
		}
		TFieldIdEnum field = result.fieldForId(0);
		if (field != null) {
			result.setFieldValue(field, r);
		}
		return successConvert(result);
	}

}
